<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<title>FNST-在线笔试系统</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="../../layui/css/layui.css" media="all">
	</head>

	<body>
		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
			<legend style="text-align: center">FNST-在线笔试系统</legend>
		</fieldset>
		<div style="padding: 20px; background-color: #F2F2F2;">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">
						<div class="layui-card-header">笔试开始确认</div>
						<div class="layui-card-body">
							<div class="layui-form-item">
								<label>笔试者：<span id="username"></span></label>
							</div>
							<div class="layui-form-item">
								<label>笔试题目，共&nbsp;&nbsp;<span id="number"></span>&nbsp;&nbsp;道</label>
							</div>
						</div>
						<div style="text-align: center;">
							<button class="layui-btn "><a style="color:white" id="EXAMBegin"  > 开始答题</a></button>
						</div>
					</div>
				</div>
			</div>
		</div>
		</div>

		<script src="../../layui/layui.js"></script>
		<script src="../js/common.js"></script>
		<script type="text/javascript" src="../../js/jquery.min.js"></script>
		<script>
			var limitTimes;
			layui.config({
				base: './../dist/'
			}).extend({
				notice: 'notice'
			});
			var del = function(obj) {
				$("#" + obj + "").remove();
			}

			function GetQueryString(name) {     
				var  reg = new  RegExp("(^|&)" + name + "=([^&]*)(&|$)");    
				var  r = window.location.search.substr(1).match(reg);     
				if(r != null) return unescape(r[2]);
				return  null;
			}
			var token = GetQueryString("token");
			layui.use(['notice'], function() {
				var notice = layui.notice; // 允许别名 toastr
						$.ajax({
							type: 'get',
							url: host() + "/getSelfInfo",
							data: {
								token: token
							},
							dataType: 'json',
							async: true,
							success: function(msg) {
								var q = msg.data["questions"];
								var n = q.split("#").length - 2;
								localStorage.setItem("userid", msg.data["id"]);
								localStorage.setItem("username", msg.data["username"]);
								localStorage.setItem("token2", GetQueryString("token"));
								limitTimes=msg.data["limitTimes"]
								$("#username").text(msg.data["username"]);
								$("#number").text(n);
							},
							error: function(msg) {
								notice.error("获取用户信息失败");
							}
						})

						$("#EXAMBegin").click(function() {
							if(limitTimes==0){
								notice.warning("笔试已经提交，不能再次开始答题");
								return;
							}
							$.ajax({
								type: "get",
								url: host() + "/startTest",
								data: {
									token: token
								},
								async: true
							});
							window.open("userExam.html");
						})
				})
		</script>
	</body>

</html>